//
//  WelcomeViewController.swift
//  Weibo
//
//  Created by 鹏 周 on 15/12/16.
//  Copyright © 2015年 ycit. All rights reserved.
//

import UIKit

class WelcomeViewController: UIViewController {

    override func loadView() {
        view = backImageView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
        
    }
    
    private func setupUI() {
    
    view.addSubview(iconView)
    view.addSubview(welcomeLabel)
        
    iconView.snp_makeConstraints { (make) -> Void in
        make.centerX.equalTo(view.snp_centerX)
        make.bottom.equalTo(view.snp_bottom).offset(-200)
        }
    
    welcomeLabel.snp_makeConstraints { (make) -> Void in
        make.centerX.equalTo(iconView.snp_centerX)
        make.top.equalTo(iconView.snp_bottom).offset(16)
        }
    }
    
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        showAnimation()
    }
    
    
  
    private func showAnimation() {
    welcomeLabel.alpha = 0
    let offset = -UIScreen.mainScreen().bounds.height+200
    iconView.snp_updateConstraints { (make) -> Void in
        make.bottom.equalTo(view.snp_bottom).offset(offset)
    }
    UIView.animateWithDuration(1.5, delay: 0, usingSpringWithDamping: 0.98, initialSpringVelocity: 9.8, options: [], animations: { () -> Void in
        self.view.layoutIfNeeded()
        }) { (_) -> Void in
            UIView.animateWithDuration(0.5, animations: { () -> Void in
                self.welcomeLabel.alpha = 1
                
            })
        }
    
    
    
}
    
    private lazy var backImageView: UIImageView = UIImageView(image: UIImage(named: "ad_background"))

    private lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    
    private lazy var welcomeLabel: UILabel = {
    let l = UILabel()
        
        l.text = "欢迎归来"
        l.font = UIFont.systemFontOfSize(16)
        l.textColor = UIColor.lightGrayColor()
        l.sizeToFit()
        return l
    
    }()
  

}
